package paper.aop;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import paper.domain.Paper;
import paper.domain.Report;
import paper.domain.Topic;
import paper.service.MessageService;

@Aspect
public class MessageInterceptor {
    /**
     * Logger for this class
     */
    private static final Logger logger = LoggerFactory.getLogger(MessageInterceptor.class);
    
    @Autowired
    private MessageService service;
    
	@Pointcut("execution(* paper.service.TopicService.submit(..))")
	private void doTopicSubmit() {}// 定义一个切入点
	
	@Pointcut("execution(* paper.service.TopicService.confirm(..))")
	private void doTopicConfirm() {}// 定义一个切入点
	
	@Pointcut("execution(* paper.service.ReportService.submit(..))")
	private void doReportSubmit() {}// 定义一个切入点
	
	@Pointcut("execution(* paper.service.ReportService.confirm(..))")
	private void doReportConfirm() {}// 定义一个切入点
	
	@Pointcut("execution(* paper.service.PaperService.submit(..))")
	private void doPaperSubmit() {}// 定义一个切入点
	
	@Pointcut("execution(* paper.service.PaperService.confirm(..))")
	private void doPaperConfirm() {}// 定义一个切入点

	@AfterReturning("doTopicSubmit() && args(topic)")
	public void doAfterTopicSubmit(Topic topic) {
//		logger.info("参数:创建人id-{},教师名称-{}",topic.getCreatorId(),topic.getMasterName());
		service.sendMessageToTeacher(topic);
	}
	
	@AfterReturning("doTopicConfirm() && args(topic)")
	public void doAfterTopicConfirm(Topic topic) {
		service.sendMessageToStudent(topic);
	}
	
	@AfterReturning("doReportSubmit() && args(report)")
	public void doAfterReportSubmit(Report report) {
		service.sendReportMessageToTeacher(report);
	}
	
	@AfterReturning("doReportConfirm() && args(report)")
	public void doAfterReportConfirm(Report report) {
		service.sendReportMessageToStudent(report);
	}
	
	@AfterReturning("doPaperSubmit() && args(paper)")
	public void doAfterPaperSubmit(Paper paper) {
		service.sendPaperMessageToTeacher(paper);
	}
	
	@AfterReturning("doPaperConfirm() && args(paper)")
	public void doAfterPaperConfirm(Paper paper) {
		service.sendPaperMessageToStudent(paper);
	}
	
}